//
//  MainViewController.swift
//  WeChat
//
//  Created by 梁迪 on 15/12/12.
//  Copyright © 2015年 梁迪. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
     let mainTarBar = MainTabBar()
    
  @objc  private func composeBtnDidClick(){
        let compose = ComposeViewController()
    
    let nav = UINavigationController(rootViewController: compose)
    
    presentViewController(nav, animated: true, completion: nil)
    
    }
    
    
    

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //tabBar 是只读属性 不能够直接进行设置 ,可以使用 KVC 进行间接赋值
        //classForCoder对象类的字符串形式
        
        print(tabBar.classForCoder)
        
       mainTarBar.composeBtn.addTarget(self, action: "composeBtnDidClick", forControlEvents: .TouchUpInside)
        setValue(mainTarBar, forKey: "tabBar")
        print(tabBar.classForCoder)
        
        
        
        
        
        
        
        addChildViewControllers()
        
        // Do any additional setup after loading the view.
    }

    private func addChildViewControllers(){
        
        addChildViewController(HomeTableViewController(), title:"首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
        
        
        
        
        
    }
    
    
    
    private func addChildViewController(vc:UIViewController,title:String, imageName:String) {
//        self.tabBar.tintColor = UIColor.orangeColor()
//        self.tabBar.tintColor = themeColor
        
       
        let nav = BasNavViewController(rootViewController: vc)
        
        vc.title = title
        
        vc.tabBarItem.image = UIImage(named: imageName)
//        nav.tabBarItem.image = UIImage(named: imageName)
//
//        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        
        
        self.addChildViewController(nav)
        
        
    }
    
    
    
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
